<template>
  <div>
    <k-form-design :tableName="tableName" :freeColumns="columnList" @save="handleSave"/>
  </div>
</template>

<script>
import { updateTable } from '@/api/free/table'
import { listColumn } from '@/api/free/column'
export default {
  name: 'FreeForm',
  components: {
  },
  
  data () {
    return {
      tableName: '',
      columnList: []
    }
  },
  created () {
  },
  mounted () {
    this.tableName = this.$route.query.tableName
    this.getColumnList()
  },
  methods: {
    getColumnList () {
      const params = {
        tableName: this.tableName
      }
      listColumn(params).then(response => {
        this.columnList = response
        this.targetKeys = this.columnList.filter(item => item.listShow === 'Y').map(item => item.id)
      })      
    },

    handleSave (data) {
      const params = {
        tableName: this.tableName,
        formJson: data
      }
      updateTable(params).then(res => {
        this.$message.success('保存成功')
      })
    }
  }
}
</script>